// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.network.packets.hit;

import java.nio.ByteBuffer;
import zombie.characters.IsoPlayer;
import zombie.characters.IsoZombie;
import zombie.core.network.ByteBufferWriter;
import zombie.core.raknet.UdpConnection;
import zombie.inventory.types.HandWeapon;
import zombie.network.PacketValidator;
import zombie.network.packets.INetworkPacket;

public class PlayerHitZombiePacket extends PlayerHitPacket implements INetworkPacket {
    protected final Zombie target = new Zombie();
    protected final WeaponHit hit = new WeaponHit();
    protected final Fall fall = new Fall();

    public PlayerHitZombiePacket() {
        super(HitCharacterPacket.HitType.PlayerHitZombie);
    }

    public void set(
        IsoPlayer wielder,
        IsoZombie _target,
        HandWeapon weapon,
        float damage,
        boolean ignore,
        float range,
        boolean isCriticalHit,
        boolean helmetFall,
        boolean hitHead
    ) {
        super.set(wielder, weapon, isCriticalHit);
        this.target.set(_target, helmetFall);
        this.hit.set(ignore, damage, range, _target.getHitForce(), _target.getHitDir().x, _target.getHitDir().y, hitHead);
        this.fall.set(_target.getHitReactionNetworkAI());
    }

    @Override
    public void parse(ByteBuffer b, UdpConnection connection) {
        super.parse(b, connection);
        this.target.parse(b, connection);
        this.hit.parse(b, connection);
        this.fall.parse(b, connection);
    }

    @Override
    public void write(ByteBufferWriter b) {
        super.write(b);
        this.target.write(b);
        this.hit.write(b);
        this.fall.write(b);
    }

    @Override
    public boolean isConsistent() {
        return super.isConsistent() && this.target.isConsistent() && this.hit.isConsistent();
    }

    @Override
    public String getDescription() {
        return super.getDescription()
            + "\n\tTarget "
            + this.target.getDescription()
            + "\n\tHit "
            + this.hit.getDescription()
            + "\n\tFall "
            + this.fall.getDescription();
    }

    @Override
    protected void preProcess() {
        super.preProcess();
        this.target.process();
    }

    @Override
    protected void process() {
        this.hit.process(this.wielder.getCharacter(), this.target.getCharacter(), this.weapon.getWeapon());
        this.fall.process(this.target.getCharacter());
    }

    @Override
    protected void postProcess() {
        super.postProcess();
        this.target.process();
    }

    @Override
    protected void react() {
        this.target.react(this.weapon.getWeapon());
    }

    @Override
    public boolean validate(UdpConnection connection) {
        return !PacketValidator.checkLongDistance(connection, this.wielder, this.target, PlayerHitZombiePacket.class.getSimpleName())
            ? false
            : PacketValidator.checkDamage(connection, this.hit, PlayerHitZombiePacket.class.getSimpleName());
    }
}
